﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Controls
{
    public partial class SwitchMenu : RadioButton
    {
        private Image mCheckImage;
        private Image mUnCheckImage;
        public SwitchMenu()
        {
            InitializeComponent();
            this.Appearance = Appearance.Button;
            this.Text = string.Empty;
            this.AutoSize = false;
            this.FlatStyle = FlatStyle.Flat;
            this.FlatAppearance.BorderSize = 0;
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.Size = new Size(40, 40);
            //this.Paint += MySwitchMenu_Paint;
            this.BackColor = SystemColors.Window;
            this.CheckedChanged += MySwitchMenu_CheckedChanged;
            this.MouseHover += SwitchMenu_MouseHover;
            this.MouseLeave += SwitchMenu_MouseLeave;
        }

        private void SwitchMenu_MouseLeave(object sender, EventArgs e)
        {
            this.FlatAppearance.BorderSize = 0;
            this.FlatAppearance.BorderColor = SystemColors.Window;
        }

        private void SwitchMenu_MouseHover(object sender, EventArgs e)
        {
            this.FlatAppearance.BorderSize = 2;
            this.FlatAppearance.BorderColor = Color.Orange;
        }

        private void MySwitchMenu_CheckedChanged(object sender, EventArgs e)
        {
            if (this.Checked)
            {
                this.BackgroundImage = mCheckImage;
            }
            else
            {
                this.BackgroundImage = mUnCheckImage;
            }
        }

        private void MySwitchMenu_Paint(object sender, PaintEventArgs e)
        {
            if (this.Checked)
            {
                this.BackgroundImage = mCheckImage;
            }
            else
            {
                this.BackgroundImage = mUnCheckImage;
            }
        }
        public Image CheckImage
        {
            set
            {
                mCheckImage = value;
            }
            get
            {
                return mCheckImage;
            }
        }
        public Image UnCheckImage
        {
            set
            {
                mUnCheckImage = value;
            }
            get
            {
                return mUnCheckImage;
            }
        }
    }
}
